namespace Microsoft.VisualStudio.EnterpriseTools.OperationDesigner
{
    using Microsoft.VisualStudio.Modeling;
    using Microsoft.VisualStudio.VirtualTreeGrid;
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Drawing.Design;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;
    using Microsoft.VisualStudio.Modeling.Diagrams;

    public class OperationDesignerTreeControl : VirtualTreeControl
    {
        private bool batchDrawItem;
        private IOperationDesignerColumnHost columnHost;
        private HybridDictionary columnTable = new HybridDictionary(5);
        private ColumnDescriptor[] currentColumns;
        private ColumnDescriptor[] defaultColumns;
        private bool ignoreDrawItem;
        private IOperationDesignerBranch insertBranch;
        private int insertIndex;
        private ArrayList invalidItems = new ArrayList();
        private bool testAggregateBranch;

        public OperationDesignerTreeControl(IOperationDesignerColumnHost columnHost)
        {
            this.columnHost = columnHost;
        }

        public void AddColumnEventHandlers(Store store)
        {
            foreach (ColumnDescriptor descriptor in this.columnTable.Values)
            {
                descriptor.AddEventHandlers(store);
            }
        }

        public static TypeEditorHost CreateTypeEditorHost(PropertyDescriptor propertyDescriptor, object instance)
        {
            TypeEditorHost host = null;
            if (propertyDescriptor != null)
            {
                UITypeEditor editor = propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
                if (editor != null)
                {
                    return new OperationDesignerInPlaceEditDropDown(editor, propertyDescriptor, instance);
                }
                TypeConverter converter = propertyDescriptor.Converter;
                if ((converter != null) && converter.GetStandardValuesSupported(null))
                {
                    host = new OperationDesignerInPlaceEditCombo(converter, propertyDescriptor, instance);
                }
            }
            return host;
        }

        public static TypeEditorHost CreateTypeEditorHost(PropertyDescriptor propertyDescriptor, object instance, TypeEditorHostEditControlStyle editControlStyle)
        {
            TypeEditorHost host = null;
            if (propertyDescriptor != null)
            {
                UITypeEditor editor = propertyDescriptor.GetEditor(typeof(UITypeEditor)) as UITypeEditor;
                if (editor != null)
                {
                    return new OperationDesignerInPlaceEditDropDown(editor, propertyDescriptor, instance, editControlStyle);
                }
                TypeConverter converter = propertyDescriptor.Converter;
                if ((converter != null) && converter.GetStandardValuesSupported(null))
                {
                    host = new OperationDesignerInPlaceEditCombo(converter, propertyDescriptor, instance, editControlStyle);
                }
            }
            return host;
        }

        protected override bool DisplayException(Exception ex)
        {
            OperationDesignerBranch.AbortVirtualTreeEdit = true;
            if (ex == CheckoutException.Canceled)
            {
                return true;
            }
            if (this.Site != null)
            {
                IUIService service = this.Site.GetService(typeof(IUIService)) as IUIService;
                if (service != null)
                {
                    service.ShowError(ex.Message);
                    return true;
                }
            }
            return base.DisplayException(ex);
        }

        protected override void Dispose(bool disposing)
        {
            if (this.columnTable != null)
            {
                foreach (ColumnDescriptor descriptor in this.columnTable.Values)
                {
                    ((IDisposable) descriptor).Dispose();
                }
                this.columnTable.Clear();
                this.columnTable = null;
            }
            base.Dispose(disposing);
        }

        private bool DoDefaultAction(IOperationDesignerBranch branch, int relIndex)
        {
            CommandID commandID = branch.GetDefaultAction(relIndex);
            if (commandID != null)
            {
                IMenuCommandService service = this.Site.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
                if (service != null)
                {
                    service.GlobalInvoke(commandID);
                    return true;
                }
            }
            return false;
        }

        internal void EnableAggregateTesting()
        {
            this.testAggregateBranch = true;
        }

        public void EndInsert()
        {
            if (this.insertBranch != null)
            {
                try
                {
                    this.insertBranch.EndInsert(this.insertIndex);
                    int currentIndex = base.CurrentIndex;
                    IBranch insertBranch = (IBranch) this.insertBranch;
                    base.Tree.DisplayDataChanged(new DisplayDataChangedData(VirtualTreeDisplayDataChanges.VisibleElements, insertBranch, this.insertIndex, -1, insertBranch.VisibleItemCount - this.insertIndex));
                }
                finally
                {
                    this.insertBranch = null;
                    this.insertIndex = -1;
                }
            }
        }

        private object[] FindAttributes(object root, System.Type attributeType, out object attributeOwner)
        {
            attributeOwner = root;
            object[] customAttributes = null;
            customAttributes = root.GetType().GetCustomAttributes(attributeType, false);
            if (((customAttributes == null) || (customAttributes.Length == 0)) && (root is PresentationElement))
            {
                ShapeElement element = root as ShapeElement;
                if ((element != null) && (element.ModelElement != null))
                {
                    customAttributes = element.ModelElement.GetType().GetCustomAttributes(attributeType, false);
                    attributeOwner = element.ModelElement;
                }
            }
            if (this.testAggregateBranch && (attributeType == typeof(OperationDesignerRootBranchAttribute)))
            {
                object[] array = new object[customAttributes.Length * 2];
                customAttributes.CopyTo(array, 0);
                customAttributes.CopyTo(array, customAttributes.Length);
                return array;
            }
            return customAttributes;
        }

        private int FindCurrentColumnOfType(ProcessKeyResult result)
        {
            for (int i = 0; i < this.currentColumns.Length; i++)
            {
                System.Type type = this.currentColumns[i].GetType();
                if (((result.ColumnType == null) || (type == result.ColumnType)) || type.IsSubclassOf(result.ColumnType))
                {
                    return i;
                }
            }
            return -1;
        }

        private ColumnDescriptor FindOrCreateColumn(System.Type columnType)
        {
            ColumnDescriptor descriptor = (ColumnDescriptor) this.columnTable[columnType];
            if (descriptor == null)
            {
                descriptor = columnType.GetConstructor(new System.Type[0]).Invoke(null) as ColumnDescriptor;
                if (descriptor == null)
                {
                    return descriptor;
                }
                if (this.columnHost != null)
                {
                    descriptor.AddEventHandlers(this.columnHost.Store);
                }
                this.columnTable[columnType] = descriptor;
                descriptor.Host = this.columnHost;
            }
            return descriptor;
        }

        private int GetLastColumnIndex(IBranch branch, int relIndex)
        {
            IMultiColumnBranch branch2 = branch as IMultiColumnBranch;
            if (branch2 == null)
            {
                return 0;
            }
            if ((branch.Features & BranchFeatures.JaggedColumns) != BranchFeatures.None)
            {
                return (branch2.GetJaggedColumnCount(relIndex) - 1);
            }
            return (branch2.ColumnCount - 1);
        }

        public void InsertCreatorNode(int absIndex, int creatorNodeIndex)
        {
            if ((absIndex < 0) || ((base.Tree != null) && (absIndex >= base.Tree.VisibleItemCount)))
            {
                throw new ArgumentOutOfRangeException("absIndex");
            }
            if (base.Tree != null)
            {
                VirtualTreeItemInfo info = base.Tree.GetItemInfo(absIndex, 0, false);
                IOperationDesignerBranch branch = info.Branch as IOperationDesignerBranch;
                if (branch != null)
                {
                    this.insertBranch = branch;
                    this.insertIndex = info.Row;
                    branch.InsertCreatorNode(info.Row, creatorNodeIndex);
                    base.Tree.DisplayDataChanged(new DisplayDataChangedData(VirtualTreeDisplayDataChanges.VisibleElements, info.Branch, this.insertIndex, -1, info.Branch.VisibleItemCount - this.insertIndex));
                    base.CurrentIndex = absIndex;
                    base.InLabelEdit = true;
                }
            }
        }

        public void InvalidateItem(int absIndex)
        {
            Microsoft.VisualStudio.EnterpriseTools.OperationDesigner.NativeMethods.Rectangle rect;
            if ((absIndex < 0) || ((base.Tree != null) && (absIndex >= base.Tree.VisibleItemCount)))
            {
                throw new ArgumentOutOfRangeException("absIndex");
            }
            Microsoft.VisualStudio.EnterpriseTools.OperationDesigner.NativeMethods.SendMessage(base.Handle, 0x198, absIndex, out rect);
            Microsoft.VisualStudio.EnterpriseTools.OperationDesigner.NativeMethods.RedrawWindow(base.Handle, ref rect, IntPtr.Zero, Microsoft.VisualStudio.EnterpriseTools.OperationDesigner.NativeMethods.RedrawWindowFlags.Erase | Microsoft.VisualStudio.EnterpriseTools.OperationDesigner.NativeMethods.RedrawWindowFlags.Invalidate);
        }

        protected override void OnDoubleClick(DoubleClickEventArgs e)
        {
            if (e.HitInfo.HitTarget == VirtualTreeHitTargets.OnItemIcon)
            {
                IOperationDesignerBranch branch = e.ItemInfo.Branch as IOperationDesignerBranch;
                if (((branch != null) && (this.Site != null)) && ((e.ItemInfo.Row != -1) && this.DoDefaultAction(branch, e.ItemInfo.Row)))
                {
                    return;
                }
            }
            base.OnDoubleClick(e);
        }

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (!this.IgnoreDrawItem)
            {
                if (this.BatchDrawItem)
                {
                    if (!this.invalidItems.Contains(e.Index))
                    {
                        this.invalidItems.Add(e.Index);
                    }
                }
                else
                {
                    base.OnDrawItem(e);
                }
            }
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (this.ProcessKeyDown(e) == ProcessKeyReturn.NotHandled)
            {
                base.OnKeyDown(e);
            }
            else
            {
                e.Handled = true;
            }
        }

        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (this.ProcessKeyPress(e.KeyChar, Control.ModifierKeys) != ProcessKeyReturn.NotHandled)
            {
                e.Handled = true;
            }
        }

        protected override void OnSelectionChanged(EventArgs e)
        {
            base.OnSelectionChanged(e);
            if (((base.CurrentColumn == 0) && !this.InsertMode) && base.ContainsFocus)
            {
                VirtualTreeItemInfo info = base.Tree.GetItemInfo(base.CurrentIndex, 0, false);
                OperationDesignerBranch branch = info.Branch as OperationDesignerBranch;
                if (branch != null)
                {
                    int elementCount = branch.ElementCount;
                    if ((info.Row >= elementCount) && ((info.Row - elementCount) < branch.CreatorNodeCount))
                    {
                        base.InLabelEdit = true;
                    }
                }
            }
        }

        public bool PopulateTree(object root)
        {
            ArrayList branchList = null;
            ITree tree = base.Tree;
            if ((tree != null) && (root != null))
            {
                object attributeOwner;
                object[] array = this.FindAttributes(root, typeof(OperationDesignerColumnAttribute), out attributeOwner);
                ColumnDescriptor[] columns = null;
                if ((array != null) && (array.Length > 0))
                {
                    int num = 0;
                    columns = new ColumnDescriptor[array.Length];
                    Array.Sort<object>(array);
                    foreach (OperationDesignerColumnAttribute attribute in array)
                    {
                        columns[num++] = this.FindOrCreateColumn(attribute.ColumnType);
                    }
                }
                if ((columns == null) && (this.defaultColumns != null))
                {
                    columns = this.defaultColumns;
                }
                if (columns != null)
                {
                    array = this.FindAttributes(root, typeof(OperationDesignerRootBranchAttribute), out attributeOwner);
                    if (array.Length > 0)
                    {
                        Array.Sort<object>(array);
                        branchList = new ArrayList(array.Length);
                        foreach (OperationDesignerRootBranchAttribute attribute2 in array)
                        {
                            System.Type branchType = attribute2.BranchType;
                            IBranch branch = null;
                            branch = Activator.CreateInstance(branchType) as IBranch;
                            if ((branch is IOperationDesignerInitializeBranch) && ((IOperationDesignerInitializeBranch) branch).Initialize(attributeOwner, columns))
                            {
                                branchList.Add(branch);
                            }
                        }
                        if (branchList.Count > 0)
                        {
                            bool flag = (this.currentColumns == null) || (columns.Length != this.currentColumns.Length);
                            if (!flag)
                            {
                                for (int i = 0; (i < this.currentColumns.Length) && !flag; i++)
                                {
                                    flag = this.currentColumns[i] != columns[i];
                                }
                            }
                            if (flag)
                            {
                                this.currentColumns = columns;
                                VariableColumnTree tree2 = tree as VariableColumnTree;
                                if (tree2 != null)
                                {
                                    tree2.ChangeColumnCount(this.currentColumns.Length);
                                    this.SetColumns(this.currentColumns);
                                }
                            }
                            tree.Root = (branchList.Count == 1) ? ((IBranch) branchList[0]) : new AggregateBranch(branchList, 0);
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        protected override bool ProcessDialogChar(char c)
        {
            bool flag2;
            try
            {
                ProcessKeyReturn return2 = this.ProcessKeyPress(c, Control.ModifierKeys);
                if (return2 != ProcessKeyReturn.KeyHandledActionOccurred)
                {
                    return (base.ProcessDialogChar(c) || (return2 == ProcessKeyReturn.KeyHandledNoAction));
                }
                flag2 = true;
            }
            catch (Exception exception)
            {
                if (Microsoft.VisualStudio.Modeling.CriticalException.IsCriticalException(exception))
                {
                    throw;
                }
                this.DisplayException(exception);
                flag2 = false;
            }
            catch
            {
                throw;
            }
            return flag2;
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            bool flag2;
            try
            {
                ProcessKeyReturn return2 = this.ProcessKeyDown(new KeyEventArgs(keyData));
                if (return2 != ProcessKeyReturn.KeyHandledActionOccurred)
                {
                    return (base.ProcessDialogKey(keyData) || (return2 == ProcessKeyReturn.KeyHandledNoAction));
                }
                flag2 = true;
            }
            catch (Exception exception)
            {
                if (Microsoft.VisualStudio.Modeling.CriticalException.IsCriticalException(exception))
                {
                    throw;
                }
                this.DisplayException(exception);
                flag2 = false;
            }
            catch
            {
                throw;
            }
            return flag2;
        }

        private bool ProcessKey(ProcessKeyResult result, IOperationDesignerBranch branch, int absIndex, int relIndex, int column)
        {
            bool flag = false;
            bool flag2 = false;
            bool inLabelEdit = base.InLabelEdit;
            if (result.Action == KeyAction.Discard)
            {
                return true;
            }
            if (result.Action == KeyAction.Handle)
            {
                TreeNavigation direction = this.TranslateNavigationDirection(result.Direction);
                if (result.StartLabelEdit)
                {
                    base.InLabelEdit = true;
                    return true;
                }
                this.BatchDrawItem = true;
                if (inLabelEdit)
                {
                    OperationDesignerBranch branch2 = branch as OperationDesignerBranch;
                    if ((branch2 != null) && (relIndex >= branch2.ElementCount))
                    {
                        inLabelEdit = base.LabelEditControl.Text.Length > 0;
                    }
                }
                try
                {
                    base.InLabelEdit = false;
                    if (base.InLabelEdit)
                    {
                        return false;
                    }
                    if (result.ExpandBranch && !base.Tree.IsExpanded(absIndex, 0))
                    {
                        if (!base.Tree.IsExpandable(absIndex, 0))
                        {
                            return false;
                        }
                        base.Tree.ToggleExpansion(absIndex, 0);
                        flag = true;
                    }
                    System.Type type = branch.GetType();
                    if (result.ColumnType != null)
                    {
                        int num = this.FindCurrentColumnOfType(result);
                        if (((direction == TreeNavigation.RightColumn) && (column < num)) || ((direction == TreeNavigation.LeftColumn) && (column > num)))
                        {
                            column = num;
                            flag2 = (((result.BranchType == null) || (type == result.BranchType)) || type.IsSubclassOf(result.BranchType)) && (((branch.GetValueSupported(relIndex, column) & OperationDesignerValueSupportedStates.SupportsKeyboardNavigation) != OperationDesignerValueSupportedStates.Default) || (branch as IBranch).IsExpandable(relIndex, column));
                        }
                        if (!flag2)
                        {
                            column = num;
                            direction = (direction == TreeNavigation.RightColumn) ? TreeNavigation.Down : TreeNavigation.Up;
                        }
                    }
                    while (!flag2)
                    {
                        int num2 = absIndex;
                        if ((direction == TreeNavigation.LeftColumn) && (column == 0))
                        {
                            absIndex--;
                            if (absIndex >= 0)
                            {
                                VirtualTreeItemInfo info = base.Tree.GetItemInfo(absIndex, 0, false);
                                column = this.GetLastColumnIndex(info.Branch, info.Row);
                            }
                        }
                        else if ((direction == TreeNavigation.RightColumn) && (column == this.GetLastColumnIndex((IBranch) branch, relIndex)))
                        {
                            absIndex++;
                            column = 0;
                        }
                        else if (result.ColumnType == null)
                        {
                            if (direction == TreeNavigation.Up)
                            {
                                absIndex--;
                                direction = TreeNavigation.LeftColumn;
                                if (absIndex >= 0)
                                {
                                    VirtualTreeItemInfo info2 = base.Tree.GetItemInfo(absIndex, 0, false);
                                    if (info2.Branch != null)
                                    {
                                        int lastColumnIndex = this.GetLastColumnIndex(info2.Branch, info2.Row);
                                        if (column > lastColumnIndex)
                                        {
                                            column = lastColumnIndex;
                                        }
                                    }
                                }
                            }
                            else if (direction == TreeNavigation.Down)
                            {
                                absIndex++;
                                direction = TreeNavigation.RightColumn;
                                if (absIndex < base.Tree.VisibleItemCount)
                                {
                                    VirtualTreeItemInfo info3 = base.Tree.GetItemInfo(absIndex, 0, false);
                                    if (info3.Branch != null)
                                    {
                                        int num4 = this.GetLastColumnIndex(info3.Branch, info3.Row);
                                        if (column > num4)
                                        {
                                            column = num4;
                                        }
                                    }
                                }
                            }
                        }
                        if ((absIndex < 0) || (absIndex >= base.Tree.VisibleItemCount))
                        {
                            break;
                        }
                        VirtualTreeCoordinate coordinate = new VirtualTreeCoordinate(absIndex, column);
                        if (absIndex == num2)
                        {
                            coordinate = base.Tree.GetNavigationTarget(direction, absIndex, column, base.ColumnPermutation);
                        }
                        if (!coordinate.IsValid)
                        {
                            break;
                        }
                        absIndex = coordinate.Row;
                        column = coordinate.Column;
                        if (num2 != absIndex)
                        {
                            VirtualTreeItemInfo info4 = base.Tree.GetItemInfo(absIndex, 0, false);
                            if ((result.Local && (branch != null)) && (branch != info4.Branch))
                            {
                                break;
                            }
                            branch = info4.Branch as IOperationDesignerBranch;
                            type = branch.GetType();
                            relIndex = info4.Row;
                        }
                        if (((branch != null) && (((result.BranchType == null) || (type == result.BranchType)) || type.IsSubclassOf(result.BranchType))) && (((branch.GetValueSupported(relIndex, column) & OperationDesignerValueSupportedStates.SupportsKeyboardNavigation) != OperationDesignerValueSupportedStates.Default) || (branch as IBranch).IsExpandable(relIndex, column)))
                        {
                            flag2 = true;
                            break;
                        }
                    }
                    if (flag2)
                    {
                        int currentIndex = base.CurrentIndex;
                        if (absIndex != currentIndex)
                        {
                            if (currentIndex != -1)
                            {
                                this.InvalidateItem(currentIndex);
                            }
                            base.CurrentIndex = absIndex;
                            flag = true;
                        }
                        if (column != base.CurrentColumn)
                        {
                            base.CurrentColumn = column;
                            flag = true;
                        }
                    }
                    if (inLabelEdit)
                    {
                        base.InLabelEdit = inLabelEdit;
                    }
                }
                finally
                {
                    this.BatchDrawItem = false;
                }
            }
            return flag;
        }

        internal ProcessKeyReturn ProcessKeyDown(KeyEventArgs e)
        {
            if (base.CurrentIndex >= 0)
            {
                int row = base.CurrentIndex;
                VirtualTreeItemInfo info = base.Tree.GetItemInfo(row, 0, false);
                IOperationDesignerBranch branch = info.Branch as IOperationDesignerBranch;
                int column = base.CurrentColumn;
                int relIndex = info.Row;
                if (branch != null)
                {
                    if (((e.KeyCode == Keys.Return) && !base.InLabelEdit) && this.DoDefaultAction(branch, relIndex))
                    {
                        return ProcessKeyReturn.KeyHandledActionOccurred;
                    }
                    ProcessKeyResult result = branch.ProcessKeyDown(relIndex, column, e);
                    if (this.ProcessKey(result, branch, row, relIndex, column))
                    {
                        return ProcessKeyReturn.KeyHandledActionOccurred;
                    }
                    if (result.Action == KeyAction.Handle)
                    {
                        return ProcessKeyReturn.KeyHandledNoAction;
                    }
                }
            }
            return ProcessKeyReturn.NotHandled;
        }

        internal ProcessKeyReturn ProcessKeyPress(char keyPressed, Keys modifiers)
        {
            if (base.CurrentIndex >= 0)
            {
                int row = base.CurrentIndex;
                VirtualTreeItemInfo info = base.Tree.GetItemInfo(row, 0, false);
                IOperationDesignerBranch branch = info.Branch as IOperationDesignerBranch;
                int column = base.CurrentColumn;
                int num3 = info.Row;
                if (branch != null)
                {
                    ProcessKeyResult result = branch.ProcessKeyPress(num3, column, keyPressed, modifiers);
                    if (this.ProcessKey(result, branch, row, num3, column))
                    {
                        return ProcessKeyReturn.KeyHandledActionOccurred;
                    }
                    if (result.Action == KeyAction.Handle)
                    {
                        return ProcessKeyReturn.KeyHandledNoAction;
                    }
                }
            }
            return ProcessKeyReturn.NotHandled;
        }

        public void RemoveColumnEventHandlers(Store store)
        {
            foreach (ColumnDescriptor descriptor in this.columnTable.Values)
            {
                descriptor.RemoveEventHandlers(store);
            }
        }

        public void SetColumns(ColumnDescriptor[] columns)
        {
            if (columns == null)
            {
                throw new ArgumentNullException("columns");
            }
            if (base.CurrentColumn >= columns.Length)
            {
                base.CurrentColumn = 0;
            }
            this.currentColumns = columns;
            float[] numArray = new float[columns.Length];
            float num = 1f;
            int length = columns.Length;
            for (int i = 0; i < columns.Length; i++)
            {
                float initialPercentage = columns[i].InitialPercentage;
                if (initialPercentage != -1f)
                {
                    if (initialPercentage > num)
                    {
                        numArray[i] = -1f;
                    }
                    else
                    {
                        num -= initialPercentage;
                        length--;
                        numArray[i] = initialPercentage;
                    }
                }
                else
                {
                    numArray[i] = -1f;
                }
            }
            float num5 = (length == 0) ? 0f : (num / ((float) length));
            VirtualTreeColumnHeader[] headers = new VirtualTreeColumnHeader[columns.Length];
            float percentage = 0f;
            for (int j = 0; j < (headers.Length - 1); j++)
            {
                if (numArray[j] == -1f)
                {
                    percentage += num5;
                }
                else
                {
                    percentage += numArray[j];
                }
                if (columns[j].ColumnIsCheckBox)
                {
                    headers[j] = new VirtualTreeColumnHeader(columns[j].Name, percentage, base.StateImageList.ImageSize.Width);
                }
                else
                {
                    headers[j] = new VirtualTreeColumnHeader(columns[j].Name, percentage);
                }
            }
            headers[headers.Length - 1] = new VirtualTreeColumnHeader(columns[headers.Length - 1].Name, 1f);
            base.SetColumnHeaders(headers, false);
        }

        private TreeNavigation TranslateNavigationDirection(NavigationDirection treeNav)
        {
            switch (treeNav)
            {
                case NavigationDirection.Up:
                    return TreeNavigation.Up;

                case NavigationDirection.Down:
                    return TreeNavigation.Down;

                case NavigationDirection.Left:
                    return TreeNavigation.LeftColumn;

                case NavigationDirection.Right:
                    return TreeNavigation.RightColumn;
            }
            return TreeNavigation.None;
        }

        public bool BatchDrawItem
        {
            get
            {
                return this.batchDrawItem;
            }
            set
            {
                this.batchDrawItem = value;
                if (!this.batchDrawItem && (this.invalidItems.Count > 0))
                {
                    if (base.Tree != null)
                    {
                        int visibleItemCount = base.Tree.VisibleItemCount;
                        foreach (int num2 in this.invalidItems)
                        {
                            if (num2 < visibleItemCount)
                            {
                                this.InvalidateItem(num2);
                            }
                        }
                    }
                    this.invalidItems.Clear();
                }
            }
        }

        internal ColumnDescriptor[] Columns
        {
            get
            {
                return this.currentColumns;
            }
        }

        public ICollection DefaultColumns
        {
            get
            {
                return ArrayList.ReadOnly(this.defaultColumns);
            }
            set
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }
                this.defaultColumns = new ColumnDescriptor[value.Count];
                value.CopyTo(this.defaultColumns, 0);
                for (int i = 0; i < this.defaultColumns.Length; i++)
                {
                    System.Type type = this.defaultColumns[i].GetType();
                    if (this.columnTable[type] == null)
                    {
                        this.columnTable[type] = this.defaultColumns[i];
                        this.defaultColumns[i].Host = this.columnHost;
                    }
                }
            }
        }

        public bool IgnoreDrawItem
        {
            get
            {
                return this.ignoreDrawItem;
            }
            set
            {
                this.ignoreDrawItem = value;
            }
        }

        public bool InsertMode
        {
            get
            {
                return (this.insertBranch != null);
            }
        }

        public VirtualTreeItemInfo SelectedItemInfo
        {
            get
            {
                int row = base.CurrentIndex;
                if ((row != -1) && (row < base.Tree.VisibleItemCount))
                {
                    return base.Tree.GetItemInfo(row, 0, false);
                }
                return new VirtualTreeItemInfo();
            }
        }
    }
}

